<!DOCTYPE html>
<html lang="zh-cn" xmlns:v-on="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="/css/pintuer.css">
    <link rel="stylesheet" href="/css/admin.css">
    <script src="/js/jquery.js"></script>
    <script src="/js/pintuer.js"></script>
    <script src="/js/vuejs-2.5.16.js"></script>
    <script src="/js/axios-0.18.0.js"></script>


</head>
<body>
<div class="panel admin-panel" id="categoryListDiv">
    <div class="panel-head"><strong class="icon-reorder">分类列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
    <div class="padding border-bottom">
        <form>
            <ul class="search" style="padding-left:10px;">
                <li> <a class="button border-main icon-plus-square-o" href="/category_add.html">添加影视分类</a> </li>
            </ul>
        </form>
    </div>
    <table class="table table-hover text-center">
        <tr>
            <th width="5%">选择</th>
            <th width="5%">排序</th>
            <th>分类名称</th>

            <th width="310">操作</th>
        </tr>
        <form >
            <tr v-for="(s,index) in pageInfo.list">
                <td style="text-align:left; padding-left:10px;"><input type="checkbox" name="ids" v-model="ids" v-bind:value="s.id" /></td>
                <td style="text-align:left; padding-left:20px;">{{index+1}}</td>
                <td>{{s.categoryName}}</td>

                <td>
                    <div class="button-group">
                        <a class="button border-main" :href="'/category_add.html?id='+s.id"><span class="icon-edit"></span>修改</a>
                        <a class="button border-red" href="javascript:void(0)" v-on:click="deleteById(s.id)">
                            <span class="icon-trash-o"></span> 删除</a>
                    </div>
                </td>
            </tr>

        </form>
        <tr>
            <td colspan="7" style="text-align:left;padding-left:20px;">
                <a href="javascript:void(0)" class="button border-red icon-trash-o" style="padding:5px 15px;" v-on:click="deleteSelect()"> 批量删除</a>
                <span>总记录数：{{pageInfo.total}}</span>
            </td>
        </tr>
          <tr>
            <td colspan="8">
                <div class="pagelist">
                    <a href="javascript:" v-on:click="pageNum = 1" v-show="pageNum != 1">首页</a>
                    <a href="javascript:" v-on:click="pageNum = pageInfo.prePage" v-show="pageInfo.hasPreviousPage">上一页</a>
                    <a href="javascript:" :class="pageNum == page ? 'current':''"
                       v-for="page in pageInfo.navigatepageNums"
                        v-on:click="pageNum = page">{{page}}</a>
                    <a href="javascript:" v-on:click="pageNum = pageInfo.nextPage" v-show="pageInfo.hasNextPage">下一页</a>
                    <a href="javascript:" v-on:click="pageNum = pageInfo.pages" v-show="pageNum != pageInfo.pages">末页</a>
                </div>
            </td>
    </table>
</div>
<script type="text/javascript">
    const app = new Vue({
        el:'#categoryListDiv',
        data:{
            pageNum:1,//当前页
            pageSize:3,//每页个数
            pageInfo:{},//当前页对象
            ids:[]
        },
        methods:{
            findByPage(){
                axios.get('/category/findByPage',{
                    params: {
                        pageNum: this.pageNum,
                        pageSize: this.pageSize,
                    }
                }).then(resp=>{
                    this.pageInfo = resp.data;
                })
            },
            deleteById(id){
                axios.delete('/category/deleteById?id='+id).then(resp=>{
                    if (resp.data == "ok"){
                        this.findByPage();
                    }
                })
            },
            deleteSelect(){
                axios.delete('/category/deleteSelect?ids='+this.ids).then(resp=>{
                    if (resp.data == "ok"){
                        this.findByPage();
                    }
                })
            }
        },
        created(){  //相当页面加载事件
            this.findByPage();
        },
        watch:{  //监视器
            pageNum(){
                this.findByPage();
            }
        }
    })
</script>
</body>
</html>